#include "calldialog.h"
#include "ui_calldialog.h"

#include <QPushButton>
#include <QMessageBox>

//--------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------
CallDialog::CallDialog(SdkManager* sdk_mgr, QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::CallDialog)
    , m_sdk_mgr(sdk_mgr)
{
    ui->setupUi(this);

    // 添加呼叫类型
    ui->comboBox_mode->addItem("p2p");
    ui->comboBox_mode->addItem("p2sp");
    ui->comboBox_mode->addItem("sfu");

    connect(ui->pushButton_call, &QPushButton::clicked, this, &CallDialog::OnCallBtnClicked);
}

//--------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------
CallDialog::~CallDialog()
{
    delete ui;
}

//--------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------
void CallDialog::OnCallBtnClicked()
{
    std::string callee = ui->lineEdit_callee->text().toStdString();
    if (callee.empty()) {
        QMessageBox::warning(this, "错误", "未未定呼叫对象！");
    }

    std::string call_mode = ui->comboBox_mode->currentText().toStdString();

    if (!m_sdk_mgr->MakeCall(call_mode, callee)) {
		reject(); // 关闭对话框，返回主窗口
    } else {
		accept(); // 关闭对话框，返回主窗口
	}
}

